package com.cn.serverline.lineicp.workshopPlan.controller;

import cn.hutool.core.lang.tree.Tree;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.serverline.lineicp.workshopPlan.entity.Configuration;
import com.cn.serverline.lineicp.workshopPlan.entity.TypesOfConsumables;
import com.cn.serverline.lineicp.workshopPlan.entity.request.ConfigurationRequest;
import com.cn.serverline.lineicp.workshopPlan.entity.request.SparePartsRequest;
import com.cn.serverline.lineicp.workshopPlan.entity.request.TypesOfConsumablesRequest;
import com.cn.serverline.lineicp.workshopPlan.service.ConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "产线构型")
@RestController
@ApiResource(name = "产线构型")
public class ConfigurationController {
    @Resource(name = "configurationServiceImpl")
    private ConfigurationService configurationService;

    /**
     * 添加产线构型
     *
     * @author 田江余
     * @date 2024年7月29日
     */
    @ApiOperation(value = "添加产线构型")
    @PostResource(name = "添加", path = "/configuration/add")
    public ResponseData<?> add(@RequestBody @Validated ConfigurationRequest configurationRequest) {
        return new SuccessResponseData<>(configurationService.add(configurationRequest));
    }

    /**
     * 删除产线构型
     *
     * @author 田江余
     * @date 2024年7月29日
     */
    @ApiOperation(value = "删除产线构型")
    @PostResource(name = "删除", path = "/configuration/delete")
    public ResponseData<?> delete(@RequestBody @Validated(ConfigurationRequest.delete.class) ConfigurationRequest configurationRequest) {
        configurationService.del(configurationRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑产线构型
     *
     * @author 田江余
     * @date 2024年7月29日
     */
    @ApiOperation(value = "编辑产线构型")
    @PostResource(name = "编辑", path = "/configuration/edit")
    public ResponseData<?> edit(@RequestBody @Validated(ConfigurationRequest.edit.class) ConfigurationRequest configurationRequest) {
        configurationService.edit(configurationRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 获取列表
     *
     * @author 田江余
     * @date 2024年7月29日
     */
    @ApiOperation(value = "查询产线构型")
    @GetResource(name = "获取列表", path = "/configuration/list")
    public ResponseData<List<Tree<Long>>> list(ConfigurationRequest configurationRequest) {
        return new SuccessResponseData<>(configurationService.tree(configurationRequest));
    }
}
